package com.strato.classloader.v1_0_0;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import com.strato.classloader.v1_0_0.activator.Activator;

public class OverallBundleContextClassLoader extends ClassLoader {

	private static OverallBundleContextClassLoader instance=new OverallBundleContextClassLoader();
	
	public static OverallBundleContextClassLoader getInstance(){
		return instance;
	}
	
	@Override
	public Class<?> loadClass(String name) {
		BundleContext context = Activator.getContext();
		Bundle[] bundles = context.getBundles();
		for(Bundle bundle:bundles){
			try {
				Class<?> clazz = bundle.loadClass(name);
				if(clazz!=null){
					return clazz;
				}
			} catch (ClassNotFoundException e) {
			}
		}
		return null;
	}

}
